package com.ylbh.modules.brand.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.brand.dto.BrandGoodsDTO;
import com.ylbh.common.pojo.brand.dto.ShoppingGoodsBrandDTO;
import com.ylbh.common.pojo.brand.vo.ShoppingBrandGoodsVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.brand.entity.ShoppingGoodsBrand;
import com.ylbh.modules.brand.service.ShoppingBrandGoodsService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 品牌管理
 * @author wjc
 * @date 2019-10-17 11:04:15
 */
@RestController
@RequestMapping("brand")
public class ShoppingBrandGoodsController {

    @Autowired
    private ShoppingBrandGoodsService shoppingBrandGoodsService;

    @ApiOperation("品牌管理列表")
    @RequestMapping("queryBrandGoodsList")
    public CommonResult<PageUtils> queryBrandGoodsList(BrandGoodsDTO brandGoodsDTO){
        PageUtils brandList =shoppingBrandGoodsService.queryBrandGoodsList(brandGoodsDTO);
        return Ref.ok(brandList);
    }

    @SysLog("批量修改品牌启用状态")
    @ApiOperation("批量修改品牌启用状态")
    @RequestMapping("modifyBrandEnableStateByIds/{batchValue}")
    public CommonResult<Void> modifyBrandEnableStateByIds(@PathVariable String batchValue, @RequestBody String[] ids){
        shoppingBrandGoodsService.modifyBrandEnableStateByIds(batchValue,ids);
        return Ref.ok();
    }

    @SysLog("修改品牌启用状态")
    @ApiOperation("修改品牌启用状态")
    @RequestMapping("modifyBrandEnableStatusById")
    public CommonResult<Void> modifyBrandEnableStatusById(@RequestBody  BrandGoodsDTO brandGoodsDTO){
        shoppingBrandGoodsService.modifyBrandEnableStatusById(brandGoodsDTO);
        return Ref.ok();
    }

    @SysLog("修改品牌显示状态")
    @ApiOperation("修改品牌显示状态")
    @RequestMapping("modifyBrandShowStateById")
    public CommonResult<Void> modifyBrandShowStateById(@RequestBody  BrandGoodsDTO brandGoodsDTO){
        shoppingBrandGoodsService.modifyBrandShowStateById(brandGoodsDTO);
        return Ref.ok();
    }

    @ApiOperation("上传Brand图片")
    @RequestMapping("uploadBrand")
    public CommonResult<String> uploadBrand(MultipartFile file){
        String url = shoppingBrandGoodsService.uploadBrand(file);
        return Ref.ok(url);
    }

    @SysLog("品牌添加")
    @ApiOperation("品牌添加")
    @PostMapping("addBrandGoods")
    @RequiresPermissions("brand:addBrandGoods")
    public CommonResult addBrandGoods(@RequestBody ShoppingGoodsBrandDTO shoppingGoodsBrandDTO){
        shoppingBrandGoodsService.addBrandGoods(shoppingGoodsBrandDTO);
        return Ref.ok();
    }

    @ApiOperation("根据ID查询品牌信息")
    @GetMapping("getBrandById/{id}")
    @RequiresPermissions("brand:getBrandById")
    public CommonResult getBrandById(@PathVariable String id) {
        ShoppingBrandGoodsVO shoppingBrandGoodsVO  =shoppingBrandGoodsService.getBrand(id);
        return Ref.ok(shoppingBrandGoodsVO);
    }

    @ApiOperation("根据ID修改品牌信息")
    @PostMapping("modifyBrandById")
    @RequiresPermissions("brand:modifyBrandById")
    public CommonResult modifyBrandById(@RequestBody ShoppingGoodsBrandDTO shoppingGoodsBrandDTO){
        shoppingBrandGoodsService.modifyBrandById(shoppingGoodsBrandDTO);
        return  Ref.ok();
    }

    @ApiOperation("删除品牌")
    @PostMapping("removeBrandByIds")
    @RequiresPermissions("brand:removeBrandByIds")
    public CommonResult removeBrandById(@RequestBody String[] ids) {
        shoppingBrandGoodsService.removeBrandById(ids[0]);
        return  Ref.ok();
    }

    @ApiOperation("通过二级分类ID获取对应的品牌数据")
    @RequestMapping("queryBrandList/{id}")
    public CommonResult<List<ShoppingGoodsBrand>> queryBrandList(@PathVariable("id") String id){
        List<ShoppingGoodsBrand> list = shoppingBrandGoodsService.queryBrandList(id);
        return Ref.ok(list);
    }
}
